package com.rljk.service.impl;

import com.rljk.common.dao.DaoSupport;
import com.rljk.domain.common.PageData;
import com.rljk.service.CommentInManager;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * @Author zhang
 * @Description  评论
 * @Date 2018/8/13 18:40
 * @Param
 * @return
 **/
@Service("commentInService")
public class CommentInService implements CommentInManager {

	@Resource(name = "daoSupport")
	private DaoSupport dao;
	
	/**新增
	 * @param pd
	 * @throws Exception
	 */
	public void save(PageData pd)throws Exception{
		dao.save("CommentInMapper.save", pd);
	}
	
	/**删除
	 * @param pd
	 * @throws Exception
	 */
	public void delete(PageData pd)throws Exception{
		dao.delete("CommentInMapper.delete", pd);
	}
	
	/**修改
	 * @param pd
	 * @throws Exception
	 */
	public void edit(PageData pd)throws Exception{
		dao.update("CommentInMapper.edit", pd);
	}

	/**通过用户的ID获取数据
	 * @param pd
	 * @throws Exception
	 */
	@SuppressWarnings("unchecked")
	@Override
	public List<PageData> getCommentListById(PageData pd) throws Exception {
		return (List<PageData>) dao.findForList("CommentInMapper.getCommentListById", pd);
	}

	/**通过文章ID获取数据
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> findByNewsdetailId(PageData pd) throws Exception {
		return (List<PageData>) dao.findForList("CommentInMapper.findByNewsdetailId", pd);
	}

	/**通过文章ID获取评论数量
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public PageData getCommentCount(String pd) throws Exception {
		return (PageData) dao.findForObject("CommentInMapper.getCommentCount", pd);
	}

	/**通过评论ID获取评论详细
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public PageData getCommentInfoById(PageData pd) throws Exception {
		return (PageData) dao.findForObject("CommentInMapper.findById", pd);
	}

	/**通过评论ID获取相关文章的评论数量
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public PageData findCommentNumByCommentId(PageData pd) throws Exception {
		return (PageData) dao.findForObject("CommentInMapper.findCommentNumByCommentId", pd);
	}

	/**通过用户ID获取自己所属文章的评论列表
	 * @param pd
	 * @throws Exception
	 */
	@Override
	public List<PageData> findCommentListByUserId(PageData pd) throws Exception {
		return (List<PageData>) dao.findForList("CommentInMapper.findCommentListByUserId", pd);
	}

}

